﻿@using OnWork.DataCenter.BLL.Standard;
@using Mapster;
<ValidateForm Model="@config"
              OnValidSubmit="@OnValidSubmit">

    <HttpConfig HttpRequest="@config.Http" TabHeight="500" />
    <div class="form-footer mt-3">
        <DialogCloseButton />
        <Button Color="Color.Primary" ButtonType="ButtonType.Submit" Icon="fa-solid fa-floppy-disk" Text="保存" />
    </div>
</ValidateForm>

@code {

    [CascadingParameter]
    private Modal? Dialog { get; set; }

    [Parameter]
    public Action? OnClose { get; set; }

    [Parameter]
    public Action<HttpToJsonConfig>? OnSave { get; set; }


    private HttpToJsonConfig config = new HttpToJsonConfig();

    [CascadingParameter(Name = "BodyContext")]
    private object? Context { get; set; }

    protected override void OnParametersSet()
    {
        base.OnParametersSet();

        if (Context is OnWork.DataCenter.BLL.Standard.HttpToJsonConfig)
        {
            config = Context as OnWork.DataCenter.BLL.Standard.HttpToJsonConfig;
        }

    }

    private async Task OnValidSubmit(EditContext item)
    {
        // do someting like save model into db

        OnSave(config);

        // 关闭弹窗
        // close Dialog
        await Dialog.Close();

        // 显示 Toast 提示弹窗
        //await Toast.Show(new ToastOption() { Title = "保存数据", Content = "保存成功，4 秒后自动关闭" });
    }

}
